define('inventory/query',function(){
	var ViewModel = function(){
		toastr.options = {
				  "closeButton": true,
				  "debug": false,
				  "progressBar": true,
				  "positionClass": "toast-top-full-width",
				  "onclick": null,
				  "showDuration": "300",
				  "hideDuration": "1000",
				  "timeOut": "3000",
				  "extendedTimeOut": "1000",
				  "showEasing": "swing",
				  "hideEasing": "linear",
				  "showMethod": "fadeIn",
				  "hideMethod": "fadeOut"
				}
		var self = this;
		var url ="/inventory/doFindInventory";
		var params = {
				"pageSize":'',
				"pageIndex":''
		};
		//第一个参数请求路径，第二个是传入的参数，第三个是回调函数 
		self.DataGrid = new RIT.eW.DataGridAjax(url, 20, self.finMenu);
		self.finMenu = function(result){
			console.log(result);
			var data = result;
			if(data && data.length && data.length>0){
				$.each(data, function (index, val) { val.checked = false; });
			}
			var items = ko.mapping.fromJS(data);
			return items();
		}
		
		//self.search();
		self.InventoryModel = ko.observable({
			orderNo:'',
			batchNumber:'',
			transferNumber:'',
			start:ko.observable(''),
			end:ko.observable('')
		});
		self.search = function(){
			self.InventoryModel().start=$("#startDate").val();
			self.InventoryModel().end = $("#endDate").val();
			var data =self.InventoryModel();
			console.log(data);
			self.DataGrid.GridParams.pageIndex(1);
			self.DataGrid.GetData(data);
		};
		self.search();
		/**搜索栏的清空*/
		self.empty = function(){
			self.InventoryModel({
				orderNo:'',
				batchNumber:'',
				transferNumber:'',
				start:'',
				end:''
			});
		}
		self.send = function(data) {
			layer.confirm('确定要重推订单？', {
				btn : [ '确定', '取消' ]
			// 按钮
			}, function() {
			var orderid = data.guid;
			console.log(orderid)
			$.ajax({
				url : '/orderhead/send',
				method : 'POST',
				contentType : 'application/json',
				data : JSON.stringify(orderid),
				success : function(result) {
					layer.closeAll();
					toastr.success(result);
					console.log(result);
				},
			});
			})
		};
		/**清单回执查看*/
		self.ReceiptModelLayer = ko.observable({
			content:''
		});
		self.look = function(data){
			console.log(data.orderid);
			$.ajax({
				url:"/inventory/doFindReceipt",
				data:JSON.stringify(data),
				type:"post",
				dataType: "json",
				contentType: "application/json;charset=UTF-8",
				success:function(result){
					var date =result.data;
					console.log(result);
					if(result.code == 1){
						toastr.error(result.msg);
						return;
					}
					if(result.code==0){
						layer.open({
							type : 1,
							title:'清单回执信息',
							skin : 'layui-layer-rim', //加上边框
							area : [ '598px', '600px' ], //宽高
							content :$('#recepipt')
						});
						self.ReceiptModelLayer(result.data);
					}
				}
			});
		}
		/**弹出框的绑定*/
		self.InventoryModelLayer = ko.observable({
			guid:'',
			billMode:'',
			orderNo:'',
			payNumber:'',
			batchNumber:'',
			transferNumber:'',
			ieType:'',
			cbeCode:''
		});
		/**修改按钮*/
		self.update = function(data){
			console.log(data);
			self.InventoryModelLayer(data);
			layer.open({
				type : 1,
				title:'运单信息',
				skin : 'layui-layer-rim', //加上边框
				area : [ '518px', '417px' ], //宽高
				content :$('#popbg')
			});
		}
		/**弹窗的提交按钮*/
		self.save = function(){
			console.log("1");
			var inventory = self.InventoryModelLayer(); 
			console.log(inventory);
			$.ajax({
				url:'/inventory/doUpdateInventory',
				data:JSON.stringify(inventory),
				type:'post',
				dataTyp:'json',
				contentType:'application/json;charset=UTF-8',
				success:function(result){
					console.log(result.result);
					if(result.result == 1){
						toastr.success("修改成功！");
					}
					if(result.result == 0){
						toastr.error("修改失败！");
					}
				}
			});
			self.search();
			self.Cancel();
		}
		/*关闭弹窗*/
		self.Cancel = function(){
			layer.close(layer.index);
		}
	};
	var model = new ViewModel();
	ko.applyBindings(model);
});